<template>
	<div>
		<el-tree :data="permiss" show-checkbox ref="tree" node-key="id" :default-expand-all="true"
			:default-checked-keys="defaultchecked" :props="{label: 'name'}">
		</el-tree>
		<el-button type="primary" plain @click="getCheckedKeys()" style="margin-top: 30px;">保存</el-button>
	</div>
</template>

<script>
	export default {
		name: 'RolePermiss',
		data() {
			return {
				permiss: [],
				defaultchecked: [],
				form: {
					roleId: 0,
					permissionId: []
				}
			}
		},
		created() {
			this.form.roleId = this.$route.query.id
			this.getData()
			this.getPermiss()
		},
		methods: {
			getData() {
				this.axios.get('/roleMenu/getByRoleId', response => {
					console.log("11111");
					
					console.log(response);
					if (response.obj) {
						this.form.roleId = response.obj.roleId
						this.defaultchecked = response.obj.menuId.split(',').map(Number)
					}
				}, {
					roleId: this.form.roleId
				})
			},
			getPermiss() {
				this.axios.get('/roleMenu/get-permiss', response => {
					// console.log(response.obj)
					console.log("222222");
					
					console.log(response);
					this.permiss = response.obj
				})
			},
			getCheckedKeys() {
				this.form.permissionId = this.$refs.tree.getCheckedKeys()
				this.axios.post('/roleMenu/save', response => {
					this.$router.push('/role')
				}, this.form)
			}
		}
	}
</script>
<style scoped>
</style>
